package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"net/http"
	"user/models"
	"user/utils"
)

type SortController struct {
	beego.Controller
}

// 榜单
func (c *SortController) Sort() {
	username := c.GetString("une")
	Price, _ := c.GetFloat("Price")
	err := models.Register(models.Sort{
		Username: username,
		Price:    Price,
	})
	if err != nil {
		c.Data["json"] = map[string]interface{}{
			"code":    -1,
			"message": err.Error(),
		}
		c.ServeJSON()
		return
	}
	data := models.GetSort()

	utils.Lpush(data)
	slice, err := utils.ZSort()
	if err != nil {
		c.Data["json"] = map[string]interface{}{
			"code":    -1,
			"message": err.Error(),
		}
		c.ServeJSON()
		return
	}
	c.Data["json"] = map[string]interface{}{
		"code":    http.StatusOK,
		"message": "success",
		"res":     slice,
	}
	c.ServeJSON()
	return

}
